#ifndef MAP_H
#define MAP_H

#include <QList>
#include "iostream"
#include <QStack>
#include <QQueue>

class Node;
class Map;

class MapIter
{
public:
    MapIter();
    MapIter(Map *);
    Node* getConnectedNodes(Node *);
private:
    Map *map;
};

class Node
{
public:
    Node();
    Node(int, int, int, int, int, int);
    Node(Node *);
    char itodir(int dir);
    int dirtoi(char dir);
    char oppDir(char dir);


    void setN(Node*, int);
    void setS(Node*, int);
    void setE(Node*, int);
    void setW(Node*, int);
    void setRoom(bool);
    void setCoord(int, int);
    void setNext(char nextNode);
    void setPrev(char prevNode);
    void setTravelDist(int dist);
    void setVisited(int dir);

    Node* getN();
    Node* getS();
    Node* getE();
    Node* getW();
    bool getRoom();
    int* getCoord();
    int* getDist();
    char getNext();
    char getPrev();
    int getTravelDist();
    Node* getPtr(int i);
    bool* getVisited();

private:
    Node* nodePts[4];
    int nodeDist[4];
    bool visited[4];
    bool room;
    int coordinates[2];
    char prev, next;
    int travelDist;

};


class Map
{
public:
    Map();
    void start(int front, int nDist, int sDist, int eDist, int wDist);
    bool addNode(int dist, int f, int b, int r, int l);
    void inferConnections(int n, int s, int e, int w);
    void setCurrentDir(char dir);
    char getCurrentDir();
    void setInFront(int front);
    int getInFront();
    void turn(char dir, int dist);
    void setRoom(char dir);
    bool similar(int val1, int val2);
    Node* same(int x, int y);
    void shortestPath();
    char itodir(int dir);
    int dirtoi(char dir);
    char oppDir(char dir);
    char whereNext();
    char checkNext();
    int recurseNext(Node *next);
    char changeDir(char dir);
    char turnDir(char dir);

private:
    Node *currentNode;
    Node *home;
    QList<Node*> nodeList;
    int inFront;
    char currentDir;
    struct travelNode
    {
        Node *node;
        char travelDir;
        bool isHome;
    };
    QStack<travelNode*> travelList;
    travelNode *travel;
};

#endif // MAP_H
